# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-markup
_pkgname=markup.ml
pkgver=1.0.3
pkgrel=3
pkgdesc="Error-recovering functional HTML5 and XML parsers and writers for OCaml"
url="https://aantron.github.io/markup.ml"
arch="all !riscv64 !loongarch64" # ocaml
license="MIT"
depends_dev="$pkgname=$pkgver-r$pkgrel"
checkdepends="ocaml-result-dev ocaml-ounit-dev"
makedepends="
	dune
	ocaml
	ocaml-bisect_ppx-dev
	ocaml-compiler-libs
	ocaml-compiler-libs-repackaged-dev
	ocaml-ppx_derivers-dev
	ocaml-ppxlib-dev
	ocaml-sexplib0-dev
	ocaml-seq-dev
	ocaml-stdlib-shims
	ocaml-uutf-dev
	ocaml-lwt-dev
	ocaml-ocplib-endian-dev
	ocaml-mmap-dev
	ocaml-bigarray-compat-dev
	"
provides="$pkgname-lwt=$pkgver-r$pkgrel"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/aantron/markup.ml/archive/$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	export OCAMLPATH=/usr/lib/ocaml
	dune build --root . @install --no-buffer --verbose
}

check() {
	dune runtest --no-buffer --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--prefix=/usr \
		--libdir=/usr/lib/ocaml

	# There's just a readme and changelog.
	rm -Rf "$pkgdir"/usr/doc
}

dev() {
	default_dev
	provides="$pkgname-lwt-dev=$pkgver-r$pkgrel"

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
1bb030fa2d79f7a7ac2d04c07c72a39e83620757b1d7d8a33eea1ec9b4c32883a67de45d1eea9bfa6533ae8076009fab9af5f180ad2be9c1fef66e3e5937048a  ocaml-markup-1.0.3.tar.gz
"
